package com.flute.icrawler.framework.framework.container;

import com.flute.icrawler.framework.framework.CrawlUrl;
import com.flute.icrawler.framework.framework.container.AdditionalUrlInformation.Additionals;
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

public class UrlNormalBinding extends TupleBinding<Object> {

	@Override
	public Object entryToObject(TupleInput arg0) {
		CrawlUrl url = new CrawlUrl(null, null);
		AdditionalUrlInformation info = new AdditionalUrlInformation();

		info.updateValue(Additionals.UpdateCount, new NumberStringValue(
				NumberStringValue.stringToNumber(arg0.readString())));
		
		url.setUrl(arg0.readString());

		return url;
	}

	@Override
	public void objectToEntry(Object arg0, TupleOutput arg1) {
		CrawlUrl url = (CrawlUrl) arg0;
		arg1.writeString(url.getAdditionalUrlInformation().getValue(
				Additionals.UpdateCount).toStringValue());
		arg1.writeString(url.getUrl());
	}

}
